package DAO;
import java.sql.*;
import Classes.*;
import java.util.*;

import DBConnection.ConnectionDB;


public class GenreDAO{
	
	 Connection con=null;
	 PreparedStatement prepStatement=null;
	 ResultSet rs=null;
	  
	 public GenreDAO(){
	   
	 }
	  
	 private Connection getConnection() throws SQLException{
		 Connection conn;
		 conn=ConnectionDB.getInstance().getConnection();
		 return conn;
	 }
	 
	 public List<Genre> getAllGenre(){
		 
		 List<Genre> AL = new ArrayList<Genre>();
		 
		 try{
			 
			 String query = "SELECT * FROM Genres ORDER BY GenreNr";
			 con = getConnection();
			 prepStatement = con.prepareStatement(query);
			 //prepStatement.setString(1, genreNr);
			 rs = prepStatement.executeQuery();
			 
			 while(rs.next()){
				 
				 AL.add(new Genre(rs.getInt("GenreNr"), rs.getString("Genre")));
			 }
			 
			 
		 }catch(SQLException sqle){sqle.printStackTrace();}
		 finally{
			 if(con != null){
					try{con.close();}catch(SQLException se){}
			 }
		 }
		 
		 return AL;
	 }

}
